import React, {useContext, useEffect, useState} from 'react';
import {Alert, ImageBackground, ScrollView, TextInput, TouchableOpacity, View,} from 'react-native';
import {Text} from 'react-native-elements';
import LocaleContext from '../libs/locale';
import WalletContext from '../libs/wallet';
import WaitingModal from '../components/WaitingModal';
import LoadingView from '../components/LoadingView';
import {
  getBalances,
  getQryZhiYaHeYue,
  getTwoSecondCalculate,
  getZhiYaHeYueQuHuiTwoInfo,
  tokenTransfer,
} from '../libs/nodes';
import {formartMoney} from '../libs/helpers';
import pool_print from '../assets/Pool/dyj.png';
import {addTx} from "../libs/pendingTxs";
import {constansts} from "../libs/constansts";
import AuthDialog from "../components/AuthDialog";
import Clipboard from "@react-native-community/clipboard";
import Toast from "react-native-simple-toast";
import BigNumber from "bignumber.js";
import {checkAddress} from "../libs/keyPair";
import AsyncStorage from "@react-native-async-storage/async-storage";
//TODO 矿池---》合约操作（添加、取回）
const PoolOp = ({navigation, route}: any) => {
  //console.warn("=================>"+JSON.stringify(route?.params?.item))

  const item = route?.params?.item;

  //钱包地址;
  const walletAddress = route?.params?.walletAddress
  //合约地址;
  const itemContract = route?.params?.itemContract
  //年化率;
  const rateYear = route?.params?.rateYear
  //能否添加转移取回
  const bShowTip = route?.params?.bShowTip || "";
  //合约状态
  const itemContractState = route?.params?.itemContractState;
  //合约数据
  const itemContractInfo = route?.params?.item || "";



  // const [item, setItem] = useState({}); //route?.params?.item
  const locale = useContext(LocaleContext);
  const wallet: any = useContext(WalletContext);
  const [balances, setBalances] = useState({SAT: '', tokens: []});
  const [bshow, setBshow] = useState(false); //TODO 2021-03-06 loading显示或隐藏状态
  const [prompt, setPrompt] = useState(''); //TODO 2021-03-06 loading对话框文字
  const [bShowLoading, setBShowLoading] = useState(false); //TODO 2021-03-06 gif—loading显示或隐藏状态
  const [refresh, setRefresh] = useState(true);//“刷新”标识
  const [authDialogVisible, setAuthDialogVisible] = useState(false);//显示输入密码


  const [opState, setOpState] = useState('1'); //操作状态（1添加；2转移；3取回）
  const [zy_pzcountError, setZy_pzcountError] = useState(''); //转移-》凭证数Err
  const [zy_pzcount, setZy_pzcount] = useState(''); //转移-》凭证数
  const [zyState, setZyState] = useState('0'); //转移->（1 25%；2 50% ；3 75% ;4 Max）
  const [zy_kypz, setZy_kypz] = useState(''); //转移-》可用凭证
  const [zy_zb, setZy_zb] = useState(''); //转移-》占比
  const [zy_zjmoneyError, setZy_zjmoneyError] = useState(''); //转移-》请输入资产金额Err
  const [zy_zjmoney, setZy_zjmoney] = useState(''); //转移-》请输入资产金额
  const [zy_hyaddrError, setZy_hyaddrError] = useState(''); //转移-》请输入合约地址Err
  const [zy_hyaddr, setZy_hyaddr] = useState(''); //转移-》请输入合约地址

  const [qh_qhpzcountError, setQh_qhpzcountError] = useState(''); //取回1-》请输入凭证数量Err
  const [receiveBackProofCount, setReceiveBackProofCount] = useState(''); //取回1-》请输入凭证数量
  const [qh_qhpzcountPercent, setQh_qhpzcountPercent] = useState('');//取回凭证的百分比;
  const [qhState, setQhState] = useState('0'); //取回1->（1 25%；2 50% ；3 75% ;4 Max）
  const [qh_kypz, setQh_kypz] = useState(''); //取回1-》可用凭证
  const [qh_zb, setQh_zb] = useState(''); //取回1-》占比
  const [qh_zcmoneyError, setQh_zcmoneyError] = useState(''); //取回1-》请输入资产金额Err
  const [qh_zcmoney, setQh_zcmoney] = useState('0'); //取回1-》禁止输入资产金额,这个金额是算出来的
  const [qhTwoList, setQhTwoList] = useState<any>([]); //取回2--列表
  const [qhTwoListShow, setQhTwoListShow] = useState(false);//取回 列表是否显示

  const [addMoneyError, setAddMoneyError] = useState(''); //添加-》请输入添加的金额Err
  const [addMoney, setAddMoney] = useState(''); //添加-》请输入添加的金额
  const [addBlc, setAddBlc] = useState(''); //添加-》余额
  //添加------------------------------------------------------总额度\\我的凭证\\年化率\\状态\质押ID
  const [searchConsDetail,setSearchConsDetail] = useState([]);
  const [currentBlockHeight,setCurrentBlockHeight] = useState(0);
  //转移凭证数量
  const [transferPZ,setTransferPZ] = useState("");
  //转移金额
  const [transferMoney,setTransferMoney] = useState("");
  //转移转向地址
  const [transferContract,setTransferContract] = useState("");


  //我的余额
  const [myMoney,setMyMoney] = useState("0");

  //利用全局变量初始化数据
  useEffect(()=>{
    console.log(`itemContractState=${itemContractState}`)
    setBalances(constansts.Balance);
    //console.log("全局变量Balance==>"+JSON.stringify(constansts.Balance))

    if(itemContractInfo!="") {
      //console.log(JSON.parse(itemContractInfo))
      setSearchConsDetail(JSON.parse(itemContractInfo));
      calculateMyMoney(JSON.parse(itemContractInfo));
    }
  },[])
  //我的余额
  useEffect(() => {

      const work = async () => {
        try {
          const balances = await getBalances(wallet.address);
          constansts.SATcount = balances.SAT;
          //console.log('getBalances===>' + JSON.stringify(balances));
          setBalances(balances);
        } catch (e) {
          //console.log('getBalances:', e);
        }
      };
      work();
    }, []);
  //合约搜索
  useEffect(() => {
      const work = async () => {
        try {
          const info = await getQryZhiYaHeYue(walletAddress,itemContract);
          //console.log("getQryZhiYaHeYue-->"+JSON.stringify(info));
          setSearchConsDetail(info);
          calculateMyMoney(info);
          // let hy = {"Address":info[1],"Contract":info[0],"Amount":info[4]}
      } catch (e) {
          //console.log('consSearch:', e);
      }
      };
      work();
    }, []);
  //二次合约取回1获取信息
  useEffect(() => {

    const work = async () => {
      try {
        //获取当前高度
        const currentBlockHeight = await getTwoSecondCalculate();
        //console.log("getTwoSecondCalculate======>>>>  "+JSON.stringify(currentBlockHeight));
        setCurrentBlockHeight(currentBlockHeight.currentBlockHeight);

        //获取二次取回的信息
        const sourceData = await getZhiYaHeYueQuHuiTwoInfo(walletAddress, itemContract);
        //console.log("getZhiYaHeYueQuHuiTwoInfo======>>>>  "+sourceData);
        const info = JSON.parse(sourceData);
        let arr = [];
        for(var i in info)
        {
          //console.log(`${i} -->${JSON.stringify(info[i])}`);
          arr.push(info[i])
        }
        //console.log("arr.length="+arr.length)
        if (arr.length > 0){
            setQhTwoList(arr);
          //console.log("qhTwoList.length="+qhTwoList.length)
            setQhTwoListShow(true);
        }else{
            setQhTwoList(arr);
            setQhTwoListShow(false);
        }
      } catch (e) {
        //console.log('getZhiYaHeYueQuHuiTwoInfo:', e);
      }
    };
    work();
  }, []);
  //获去当前高度 --获取信息 确认状态 是否 可取回;
  useEffect(() => {
    const work = async () => {
      try {
        const sourceData = await getTwoSecondCalculate();
        //console.log("getTwoSecondCalculate======>>>>  "+JSON.stringify(sourceData));
        setCurrentBlockHeight(sourceData.currentBlockHeight);
        //console.log("sourceData.currentBlockHeight="+sourceData.currentBlockHeight)
      } catch (e) {
        //console.log('getTwoSecondCalculate:', e);
      }
    };
    const t = setInterval(work,15000);
    return ()=> clearInterval(t)
    }
  , []);

  // 我的占比
  const calculateMyPercent = ()=>{
    return parseFloat(searchConsDetail[5]) / parseFloat(searchConsDetail[6])
  }

  // 我的收益
  const calculateMyIncome = (percent:any)=>{
      const myIncomeValue = (calculateMyPercent() * parseFloat(searchConsDetail[3])) * percent
      setQh_zcmoney(myIncomeValue+'')
      var resContract = (parseFloat(searchConsDetail[5])*percent).toString();
      resContract = new BigNumber(resContract).toFormat(8).replace(/,/g, "");
      setReceiveBackProofCount(new BigNumber(resContract).toFormat().replace(/,/g, ""))
  }

  // 我的余额
  const calculateMyMoney = (item:any)=>{
    const myMoney = formartMoney((parseFloat(item[5])/parseFloat(item[6])*parseFloat(item[3])).toString(),8);
    //console.log("myMoney==>"+myMoney+"  "+item[5]+" "+item[6]+"  "+item[3])
    setMyMoney(myMoney);
  }

  // 更新取回资产
  const updateReceiveBackProofCount=(proofCount:any)=>{
    //输入的凭证数量 / 可用的凭证数量 拿到这个百分比  调用calculateMyIncom 更新取回资产输入框
    const percent = proofCount / searchConsDetail[5]
    setReceiveBackProofCount(proofCount+"")
    if (percent > 1){
      calculateMyIncome(1);
    }else{
      calculateMyIncome(percent);
    }
  }

  //阻拦交易提示信息
  const showNeedExcuteContent=()=>{
    return locale?._('pool.op.pooling')+":"+ constansts.poolShowInfo.addressIn + ' \n'+ constansts.poolShowInfo.operateType + ' ' + constansts.poolShowInfo.requestMoney+"\n"+locale?._("pool.op.tryLater") ;
  }

  //“添加”按钮
  const onPressAdd = async (addMoney:any) => {
    try {
      var temp=0;
      try {
        addMoney = formartMoney(addMoney,8);
        addMoney = (new BigNumber(addMoney).toFormat().replace(/,/g, ""));
        if (addMoney == "" || parseFloat(addMoney) < 1000 || parseFloat(addMoney)>parseFloat(constansts.Balance.SAT)) {
          temp=1;
        }
      }catch (e) {
        temp=1;
      }

      if(temp==1)
      {
        Alert.alert("",(locale?._("pool.op.addMoneyError") as any),[{text: (locale?._('Assets.send.OK') as any)}]);
        return;
      }

      if(parseFloat(addMoney)+0.002>parseFloat(constansts.Balance.SAT))
      {
        Alert.alert("",(locale?._("serviceChargeError") as any),[{text: (locale?._('Assets.send.OK') as any)}]);
        return ;
      }


      if(bShowTip && constansts.poolShowTip){
          //locale?._('Pool.op.excuting')
          Alert.alert('', showNeedExcuteContent(),[{text:locale?._('Assets.send.OK'),onPress:()=>{
          }}]);
          return;
      }
      setBshow(true); //TODO 2021-03-25
      //TODO 质押合约添加//{keypairSeed:wallet.seed，Sender:钱包地址，tokenAddress:合约地址，Data:addLiquidity("添加金额","添加金额")，}
      const tx = await tokenTransfer(wallet.seed, wallet.address, itemContract, `addLiquidity("${addMoney}","${addMoney}")`,'',"");

      //添加进入列表
      if (tx.reason!=1)
      {
        console.log("false reason="+tx.reason+"     "+ tx.data);
        setBshow(false);//TODO 2021-03-06
        Alert.alert((tx.reason as any).toString(), locale?._('Assets.send.sendFail'),[{text: (locale?._('Assets.send.OK') as any)}]);
        return;
      }
      else
      {
        await addTx(tx);
        (constansts.tranHY as any).push(tx);
        await AsyncStorage.setItem("tranHY",JSON.stringify(constansts.tranHY));
      }

      setBshow(false); //TODO 2021-03-25
      //console.log("onPressAdd ====>>>>" + JSON.stringify(tx));
      Alert.alert('', locale?._('Assets.send.sendSuccess'), [
        {text: locale?._('Assets.send.OK'), onPress: () =>
        {
          console.log("开始数据添加")
          constansts.poolShowInfo.addressIn = tx.hash;
          (constansts.poolShowInfo.operateType as any)=locale?._("pool.zyhy.addHY");
          constansts.poolShowInfo.requestMoney ="amount："+addMoney;
          route.params.updateData(true,tx.hash,constansts.poolShowInfo.operateType," amount："+addMoney);
          navigation.goBack();
        }},
      ]);
      // navigation.replace('Txs', { kind: 'Pending' });
    } catch (e) {
      //console.log('onPressAdd:', e);
      Alert.alert('', 'onPressAdd---Err');
    }
  };

  //“转移”按钮
  const onPressMove = async (MovePZ:any) => {
    var temp=0;
    try {
      const voucher = parseFloat(searchConsDetail[5]);
      console.log("transferPZValue ==>"+MovePZ)
      MovePZ = formartMoney(MovePZ,8);
      MovePZ = (new BigNumber(MovePZ).toFormat().replace(/,/g, ""));
      console.log("取回第一次==>"+MovePZ+"   "+voucher)
      if (MovePZ == "" || parseFloat(MovePZ) <= 0 || parseFloat(MovePZ) > voucher ) {
        temp=1;
      }
    }catch (e) {
      temp=1;
    }
    // console.log(1);
    if(0.002>parseFloat(constansts.Balance.SAT))
    {
      Alert.alert("",(locale?._("serviceChargeError") as any),[{text: (locale?._('Assets.send.OK') as any)}]);
      return ;
    }
    // console.log(2);
    if(temp==1)
    {
      Alert.alert("",(locale?._("pool.op.moveMoneyError") as any),[{text: (locale?._('Assets.send.OK') as any)}]);
      return;
    }
    // console.log(3);
    if(transferContract=="" || !checkAddress(transferContract))
    {
      Alert.alert("",(locale?._("pool.op.moveAddressError") as any),[{text: (locale?._('Assets.send.OK') as any)}]);
      return;
    }
    // console.log(4);
    if(bShowTip && constansts.poolShowTip){
      //locale?._('Pool.op.excuting')
      Alert.alert('', showNeedExcuteContent(),[{text:locale?._('Assets.send.OK'),onPress:()=>{
        }}]);
      return;
    }
    // console.log(5);
    setBshow(true);
    // var tx :any;
    console.log("开始转移交易")
    const tx = await tokenTransfer(wallet.seed, wallet.address, itemContract, `diversionLiquidity("${MovePZ}","${transferContract}")`,"moveSAT(\""+formartMoney(transferMoney,8)+"\")","");
    console.log(tx);
    //添加进入列表
    if (tx.reason!=1)
    {
      console.log("false reason="+tx.reason+"     "+ tx.data);
      setBshow(false);//TODO 2021-03-06
      Alert.alert((tx.reason as any).toString(), locale?._('Assets.send.sendFail'),[{text: (locale?._('Assets.send.OK') as any)}]);
      return;
    }
    else
    {
      console.log("这笔交易成功广播了")
      await addTx(tx);
      (constansts.tranHY as any).push(tx);
        await AsyncStorage.setItem("tranHY",JSON.stringify(constansts.tranHY));
    }

    setBshow(false); //TODO 2021-03-25
    //console.log("onPressQhOne() ====>>>> "+JSON.stringify(tx));
    Alert.alert('', locale?._('Assets.send.sendSuccess'), [
      {text: (locale?._('Assets.send.OK') ), onPress: () =>
        {
          constansts.poolShowInfo.addressIn = tx.hash;
          (constansts.poolShowInfo.operateType as any)=locale?._("pool.zyhy.moveHY");
          constansts.poolShowInfo.requestMoney ="amount："+transferMoney;
          route.params.updateData(true,tx.hash,constansts.poolShowInfo.operateType,transferMoney);
          navigation.goBack();
        }},
    ]);


  };

  //“取回（第一次）”按钮  质押合约取回// keypairSeed:wallet.seed，Sender:钱包地址，tokenAddress:合约地址，Data:removeLiquidity("要取回份额")，}
  const onPressQhOne = async (receiveMoney:any) => {
    try {
      var temp=0;
      try {
        const voucher = parseFloat(searchConsDetail[5]);
        console.log("receiveMoney Value ==>"+receiveMoney)
        receiveMoney = formartMoney(receiveMoney,8);
        receiveMoney = (new BigNumber(receiveMoney).toFormat().replace(/,/g, ""));
        console.log("取回第一次==>"+receiveMoney+"   "+voucher )
        if (receiveMoney == "" || parseFloat(receiveMoney) <= 0 || parseFloat(receiveMoney) > voucher ) {
          temp=1;
        }
      }catch (e) {
        temp=1;
      }

      if(temp==1)
      {
        Alert.alert("",(locale?._("pool.op.releaseMoneyError") as any),[{text: (locale?._('Assets.send.OK') as any)}]);
        return;
      }

      if(0.002>parseFloat(constansts.Balance.SAT))
      {
        Alert.alert("",(locale?._("serviceChargeError") as any),[{text: (locale?._('Assets.send.OK') as any)}]);
        return ;
      }
      if(bShowTip && constansts.poolShowTip){
        //locale?._('Pool.op.excuting')
        Alert.alert('', showNeedExcuteContent(),[{text:locale?._('Assets.send.OK'),onPress:()=>{
          }}]);
        return;
      }
      setBshow(true); //TODO 2021-03-25
      const tx = await tokenTransfer(wallet.seed, wallet.address, itemContract, `removeLiquidity("${receiveMoney}")`,"removeSAT(\""+qh_zcmoney+"\")","");

      //添加进入列表
      if (tx.reason!=1)
      {
        console.log("false reason="+tx.reason+"     "+ tx.data);
        setBshow(false);//TODO 2021-03-06
        Alert.alert((tx.reason as any).toString(), locale?._('Assets.send.sendFail'),[{text: (locale?._('Assets.send.OK') as any)}]);
        return;
      }
      else
      {
        console.log("这笔交易成功广播了")
        await addTx(tx);
        (constansts.tranHY as any).push(tx);
        await AsyncStorage.setItem("tranHY",JSON.stringify(constansts.tranHY));
      }

      setBshow(false); //TODO 2021-03-25
      //console.log("onPressQhOne() ====>>>> "+JSON.stringify(tx));
      Alert.alert('', locale?._('Assets.send.sendSuccess'), [
        {text: (locale?._('Assets.send.OK') ), onPress: () =>
        {
          constansts.poolShowInfo.addressIn = tx.hash;
          (constansts.poolShowInfo.operateType as any)=locale?._("pool.zyhy.releaseHY");
          constansts.poolShowInfo.requestMoney ="amount："+receiveBackProofCount;
          route.params.updateData(true,tx.hash,constansts.poolShowInfo.operateType,receiveBackProofCount);
          navigation.goBack();
        }},
      ]);
      // navigation.replace('Txs', { kind: 'Pending' });
    } catch (e) {
      console.log('onPressQhOne:', e);
      setBshow(false); //TODO 2021-03-25
      Alert.alert('', 'onPressQhOne---Err');
    }
  };

  //“取回（第二次）”按钮
  const onPressQhTwo = async (retrieved:string,amount:string) => {
    try {
      if(bShowTip && constansts.poolShowTip){
        //locale?._('Pool.op.excuting')
        Alert.alert('', showNeedExcuteContent(),[{text:locale?._('Assets.send.OK'),onPress:()=>{
          }}]);
        return;
      }

      if(0.002>parseFloat(constansts.Balance.SAT))
      {
        Alert.alert("",(locale?._("serviceChargeError") as any),[{text: (locale?._('Assets.send.OK') as any)}]);
        return ;
      }

      setBshow(true); //TODO 2021-03-06
      // setBShowLoading(true);//TODO 2021-03-06
      //TODO 二次合约取回//{keypairSeed:wallet.seed，Sender:钱包地址，tokenAddress:合约地址，Data:retrieved("序号")，}
      const tx = await tokenTransfer(wallet.seed, wallet.address, itemContract, `retrieved("${retrieved}")`,'amount：'+amount,"");


      //添加进入列表
      if (tx.reason!=1)
      {
        //console.log("false reason="+tx.reason+"     "+ tx.data);
        setBshow(false);//TODO 2021-03-06
        Alert.alert((tx.reason as any).toString(), locale?._('Assets.send.sendFail'),[{text: (locale?._('Assets.send.OK') as any)}]);
        return;
      }
      else
      {
        await addTx(tx);
        (constansts.tranHY as any).push(tx);
        await AsyncStorage.setItem("tranHY",JSON.stringify(constansts.tranHY));
      }



      setBshow(false); //TODO 2021-03-06
      // setBShowLoading(false);//TODO 2021-03-06
      Alert.alert('', locale?._('Assets.send.sendSuccess'), [
        // {text: JSON.stringify(tx), onPress: () => {}},
        {text: locale?._('Assets.send.OK'), onPress: () =>
        {
          constansts.poolShowInfo.addressIn = tx.hash;
          (constansts.poolShowInfo.operateType as any)=locale?._("pool.zyhy.getHY");
          constansts.poolShowInfo.requestMoney = "amount："+amount;
          route.params.updateData(true,tx.hash,constansts.poolShowInfo.operateType,"amount："+amount);
          navigation.goBack();
        }},
      ]);
      //console.log("onPressQhTwo =====>>>>>" + JSON.stringify(tx));
      // navigation.replace('Txs', { kind: 'Pending' });
    } catch (e) {
      //console.log('onPressQhTwo:', e);
      Alert.alert('', 'onPressQhTwo---Err');
    }
  };

  //撤销
  const recallContract = async (recallHeight: any, amount: any)=>{
    try {
      if(bShowTip && constansts.poolShowTip){
        //locale?._('Pool.op.excuting')
        Alert.alert('', showNeedExcuteContent(),[{text:locale?._('Assets.send.OK'),onPress:()=>{
          }}]);
        return;
      }

      if(0.002>parseFloat(constansts.Balance.SAT))
      {
        Alert.alert("",(locale?._("serviceChargeError") as any),[{text: (locale?._('Assets.send.OK') as any)}]);
        return ;
      }
      setBshow(true); //TODO 2021-03-06
      // setBShowLoading(true);//TODO 2021-03-06
      //TODO 二次合约撤销取回//{keypairSeed:wallet.seed，Sender:钱包地址，tokenAddress:合约地址，Data:retrieved("序号")，}
      const tx = await tokenTransfer(wallet.seed, wallet.address, constansts.PledgeFactory, `cancel("${itemContract}","${recallHeight}")`,'amount：'+amount,"");


      //添加进入列表
      if (tx.reason!=1)
      {
        //console.log("false reason="+tx.reason+"     "+ tx.data);
        setBshow(false);//TODO 2021-03-06
        Alert.alert(tx.reason, locale?._('Assets.send.sendFail'),[{text: (locale?._('Assets.send.OK') as any)}]);
        return;
      }
      else
      {
        await addTx(tx);
        (constansts.tranHY as any).push(tx);
        await AsyncStorage.setItem("tranHY",JSON.stringify(constansts.tranHY));
      }
      setBshow(false); //TODO 2021-03-06
      // setBShowLoading(false);//TODO 2021-03-06
      Alert.alert('', locale?._('Assets.send.sendSuccess'), [
        // {text: JSON.stringify(tx), onPress: () => {}},
        {text: locale?._('Assets.send.OK'), onPress: () =>
          {
            constansts.poolShowInfo.addressIn = tx.hash;
            (constansts.poolShowInfo.operateType as any)=locale?._("pool.zyhy.recallHY");
            constansts.poolShowInfo.requestMoney = "amount："+amount;
            route.params.updateData(true,tx.hash,constansts.poolShowInfo.operateType,"amount："+amount);
            navigation.goBack();
          }},
      ]);
      //console.log("onPressQhTwo =====>>>>>" + JSON.stringify(tx));
      // navigation.replace('Txs', { kind: 'Pending' });
    } catch (e) {
      console.log('onRecall:', e);
      Alert.alert('', 'onRecall---Err');
    }
  };

  //获取剩余时间 时间 = (序号-当前高度)*15秒;
  const getRemainTime = (serialNumber:any)=>{
    //console.log("锁仓高度="+serialNumber)
    //console.log("当前高度="+currentBlockHeight)
    if(serialNumber < currentBlockHeight){
      return  locale?._('pool.op.Retrieve')
    }
    var time = Math.ceil(((serialNumber - currentBlockHeight)*15)/60).toFixed();
    if(parseInt(time)<60)
    {
      return time+(locale?._('pool.op.minute') as any);
    }
    else if(parseInt(time)<60*24)
    {
      var timeh = Math.ceil(((serialNumber - currentBlockHeight)*15)/(60*60)).toFixed();
      return timeh+(locale?._('pool.op.hour') as any);
    }
    else
    {
      var timed = Math.ceil(((serialNumber - currentBlockHeight)*15)/(60*60*24)).toFixed();
      return timed+(locale?._('pool.op.day') as any);
    }

  }

  //输入密码
  const onAuthDialogClose = (validated: boolean) => {
    setAuthDialogVisible(false);

    if (validated) {

    }
  }

  //复制
  const onCopy = ( data:any) => {
    if(data=="")
      return;
    Clipboard.setString(data);
    Toast.show(locale?._('copied') as string);
  };

  //质押合约  一排按钮--->>（添加、转移、取回） locale?._('My.security')
  return (
    <ScrollView>
    <View style={{flex: 1, backgroundColor: '#F3F4F5'}}>
      <View style={{backgroundColor: '#7367E3', height: 160}}>
        <View
          style={{
            backgroundColor: '#FFFFFF',
            width: 330,
            height: 80,
            margin: 16,
            borderRadius: 20,
            borderWidth: 2,
            borderColor: '#FFFFFF',
            alignSelf: 'center',
            justifyContent: 'center',
          }}>
          <View
            style={{
              width: 280,
              height: 50,
              borderRadius: 20,
              borderWidth: 2,
              borderColor: '#F3F4F5',
              flexDirection: 'row',
              backgroundColor: '#F3F4F5',
              alignSelf: 'center',
            }}>
            {/***添加*****/}
            {opState === '1' ? (
              <View
                style={{
                  flex: 1,
                  height: 50,
                  justifyContent: 'center',
                  alignItems: 'center',
                  backgroundColor: '#7367E3',
                  borderWidth: 2,
                  borderRadius: 20,
                  borderColor: '#7367E3',
                }}>
                <Text
                  style={{
                    fontSize: 16,
                    color: '#FFFFFF',
                    fontWeight: 'bold',
                    textAlign: 'center',
                  }}>
                  {locale?._('Pool.op.btn_create')}
                </Text>
              </View>
            ) : (
              <TouchableOpacity
                style={{
                  flex: 1,
                  height: 50,
                  justifyContent: 'center',
                  alignItems: 'center',
                  borderRadius: 20,
                  borderWidth: 2,
                  borderColor: '#F3F4F5',
                }}
                onPress={() => {
                  setOpState('1');
                }}>
                <Text
                  style={{
                    fontSize: 16,
                    color: '#8a8a8a',
                    fontWeight: 'bold',
                    textAlign: 'center',
                  }}>
                  {locale?._('Pool.op.btn_create')}
                </Text>
              </TouchableOpacity>
            )}
            {/***转移*****/}
            {opState === '2' ? (
              <View
                style={{flex: 1,height: 50,justifyContent: 'center',alignItems: 'center',backgroundColor: '#7367E3',borderWidth: 2,borderRadius: 20,borderColor: '#7367E3',
                }}>
                <Text
                  style={{fontSize: 16,color: '#FFFFFF',fontWeight: 'bold',textAlign: 'center'}}>
                  {locale?._('Pool.op.btn_modife')}
                </Text>
              </View>
            ) : (
              <TouchableOpacity
                style={{
                  flex: 1,
                  height: 50,
                  justifyContent: 'center',
                  alignItems: 'center',
                  borderRadius: 20,
                  borderWidth: 2,
                  borderColor: '#F3F4F5',
                }}
                onPress={() => {
                  setOpState('2');
                }}>
                <Text
                  style={{
                    fontSize: 16,
                    color: '#8a8a8a',
                    fontWeight: 'bold',
                    textAlign: 'center',
                  }}>
                  {locale?._('Pool.op.btn_modife')}
                </Text>
              </TouchableOpacity>
            )}

            {/***取回*****/}
            {opState === '3' ? (
              <View
                style={{flex: 1,
                  height: 50,
                  justifyContent: 'center',
                  alignItems: 'center',
                  backgroundColor: '#7367E3',
                  borderWidth: 2,
                  borderRadius: 20,
                  borderColor: '#7367E3',
                }}>
                <Text
                  style={{fontSize: 16,
                    color: '#FFFFFF',
                    fontWeight: 'bold',
                    textAlign: 'center',
                  }}>
                  {locale?._('Pool.op.btn_delete')}
                </Text>
              </View>
            ) : (
              <TouchableOpacity
                style={{flex: 1,
                  height: 50,
                  justifyContent: 'center',
                  alignItems: 'center',
                  borderRadius: 20,
                  borderWidth: 2,
                  borderColor: '#F3F4F5',
                }}
                onPress={() => {
                  setOpState('3');
                }}>
                <Text
                  style={{fontSize: 16,
                    color: '#8a8a8a',
                    fontWeight: 'bold',
                    textAlign: 'center',
                  }}>
                  {locale?._('Pool.op.btn_delete')}
                </Text>
              </TouchableOpacity>
            )}
          </View>
        </View>
      </View>

      {/*******添加--********/}
      {opState === '1' ? (
        <View>
          <View
            style={{marginTop: -40,
              height: 150,
              marginLeft: 16,
              marginRight: 16,
              marginBottom: 16,
              backgroundColor: '#FFFFFF',
              borderColor: '#FFFFFF',
              borderRadius: 10,
              borderWidth: 1,
            }}>
            {/**确认金额**/}
            <Text
              style={{fontSize: 18,
                color: '#14141A',
                fontWeight: 'bold',
                marginLeft: 16,
                marginTop: 8,
              }}>
              {locale?._('Pool.op.qrmoney')}
            </Text>
            {/***请输入添加的金额 右边有一个SAT图标***/}
            <View
              style={{width: 300,
                height: 48,
                backgroundColor: '#ffffff',
                marginTop: 20,
                marginLeft: 12,
                borderWidth: 1,
                borderRadius: 10,
                borderColor: '#ffffff',
                flexDirection: 'row',
              }}>
              <TextInput
                underlineColorAndroid={'transparent'}
                placeholder={locale?._('Pool.op.qrmoneyHint')}
                // errorMessage={addMoneyError}
                  value={addMoney}
                onChangeText={(value) => {
                  // @ts-ignore
                  value = value.match(/^\d*(\.?\d{0,8})/g)[0];
                  setAddMoney(value)
                  }
                }
                style={{width: 240, fontSize: 17}}
              />
              <Text
                style={{fontSize: 16,
                  color: '#9A9AA7',
                  alignSelf: 'center',
                  borderWidth: 1,
                  borderColor: '#9A9AA7',
                  borderRadius: 10,
                  paddingLeft: 10,
                  paddingRight: 10,
                  paddingTop: 2,
                  paddingBottom: 2,
                  marginRight: 10,
                }}>
                SAT
              </Text>
            </View>

            {/**余额**/}
            <Text
              style={{ marginTop: 8,
                marginLeft: 16,
                fontSize: 18,
                color: '#8E8E8E',
              }}>
              {locale?._('Pool.op.blc')}
              <Text style={{fontSize: 18, color: '#7367E3'}}>
                {formartMoney(balances.SAT, 4)}
              </Text>
            </Text>
          </View>

          {/***添加二“质押” 信息****/}
          <View>
            <View
              style={{ margin: 15,
                borderColor: '#FFFFFF',
                borderWidth: 1,
                borderRadius: 20,
                marginTop: 5,
                backgroundColor: '#FFFFFF',
              }}
              >
              <View style={{flexDirection: 'row'}}>
                <View style={{flex: 1, marginLeft: 15}}>
                  {/**资金池**/}
                  <Text style={{fontSize: 14, color: '#999999', marginTop: 8}}>
                    {locale?._('Pool.zyhy_zjc')}
                  </Text>
                  <Text
                    style={{ fontSize: 14,
                      color: '#14141A',
                      fontWeight: 'bold',
                      marginTop: 8,
                    }}>
                    {searchConsDetail[4]?searchConsDetail[4]:0}
                  </Text>
                  {/**我的凭证**/}
                  <Text style={{fontSize: 14, color: '#999999', marginTop: 8}}>
                    {locale?._('Pool.zyhy_mypz')}
                  </Text>
                  <Text
                    style={{
                      fontSize: 14,
                      color: '#14141A',
                      fontWeight: 'bold',
                      marginTop: 8,
                    }}>
                    {searchConsDetail[5]?searchConsDetail[5]:0}
                  </Text>
                </View>
                <View style={{flex: 1, marginRight: 15}}>
                  <View style={{flexDirection: 'row'}}>
                    <View>
                      {/**年化率**/}
                      <Text
                        style={{fontSize: 14, color: '#999999', marginTop: 8}}>
                        {locale?._('Pool.zyhy_nhl')}
                      </Text>
                      <Text
                        style={{
                          fontSize: 14,
                          color: '#F92360',
                          fontWeight: 'bold',
                          marginTop: 8,
                        }}>
                        {rateYear}%
                      </Text>
                    </View>
                    <View>
                      {/**状态**/}
                      <Text
                        style={{
                          fontSize: 14,
                          color: '#999999',
                          marginTop: 8,
                          marginLeft: 20,
                        }}>
                        {locale?._('Pool.zyhy_zt')}
                      </Text>
                      <View style={{flexDirection: 'row'}}>
                        <View
                            style={{flexDirection: 'row',marginTop: 10,marginLeft: 20}}>
                        {
                          itemContractState > 0 ?
                              <View style={{
                                backgroundColor: '#1B9749', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                              :
                              <View style={{
                                backgroundColor: '#ffffff', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                        }
                        {
                          itemContractState >= 4 ?
                              <View style={{
                                backgroundColor: '#1B9749', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                              :
                              <View style={{
                                backgroundColor: '#ffffff', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                        }
                        {
                          itemContractState >=8 ?
                              <View style={{
                                backgroundColor: '#1B9749', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                              :
                              <View style={{
                                backgroundColor: '#ffffff', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                        }
                        {
                          itemContractState >=12 ?
                              <View style={{
                                backgroundColor: '#1B9749', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                              :
                              <View style={{
                                backgroundColor: '#ffffff', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                        }
                        {
                          itemContractState >=16 ?
                              <View style={{
                                backgroundColor: '#1B9749', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                              :
                              <View style={{
                                backgroundColor: '#ffffff', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                        }
                        {
                          itemContractState >=20 ?
                              <View style={{
                                backgroundColor: '#1B9749', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                              :
                              <View style={{
                                backgroundColor: '#ffffff', width: 4, height: 16, marginRight: 2,
                                borderWidth: 1, borderRadius: 2, borderColor: '#1B9749',
                              }}/>
                        }
                        </View>
                        {/*{*/}
                        {/*  itemContractState ? (*/}
                        {/*    <View*/}
                        {/*        style={{flexDirection: 'row',marginTop: 10,marginLeft: 20}}>*/}
                        {/*      <View*/}
                        {/*          style={{backgroundColor: '#1B9749',width: 4,height: 16,marginRight: 2,*/}
                        {/*            borderWidth: 1,borderRadius: 2,borderColor: '#1B9749',}}*/}
                        {/*      />*/}
                        {/*      <View*/}
                        {/*          style={{*/}
                        {/*            backgroundColor: '#1B9749',*/}
                        {/*            width: 4,*/}
                        {/*            height: 16,*/}
                        {/*            marginRight: 2,*/}
                        {/*            borderWidth: 1,*/}
                        {/*            borderRadius: 2,*/}
                        {/*            borderColor: '#1B9749',*/}
                        {/*          }}*/}
                        {/*      />*/}
                        {/*      <View*/}
                        {/*          style={{*/}
                        {/*            backgroundColor: '#1B9749',*/}
                        {/*            width: 4,*/}
                        {/*            height: 16,*/}
                        {/*            marginRight: 2,*/}
                        {/*            borderWidth: 1,*/}
                        {/*            borderRadius: 2,*/}
                        {/*            borderColor: '#1B9749',*/}
                        {/*          }}*/}
                        {/*      />*/}
                        {/*      <View*/}
                        {/*          style={{*/}
                        {/*            backgroundColor: '#1B9749',*/}
                        {/*            width: 4,*/}
                        {/*            height: 16,*/}
                        {/*            marginRight: 2,*/}
                        {/*            borderWidth: 1,*/}
                        {/*            borderRadius: 2,*/}
                        {/*            borderColor: '#1B9749',*/}
                        {/*          }}*/}
                        {/*      />*/}
                        {/*      <View*/}
                        {/*          style={{*/}
                        {/*            backgroundColor: '#1B9749',*/}
                        {/*            width: 4,*/}
                        {/*            height: 16,*/}
                        {/*            marginRight: 2,*/}
                        {/*            borderWidth: 1,*/}
                        {/*            borderRadius: 2,*/}
                        {/*            borderColor: '#1B9749',*/}
                        {/*          }}*/}
                        {/*      />*/}
                        {/*      <View*/}
                        {/*          style={{*/}
                        {/*            backgroundColor: '#1B9749',*/}
                        {/*            width: 4,*/}
                        {/*            height: 16,*/}
                        {/*            borderWidth: 1,*/}
                        {/*            borderRadius: 2,*/}
                        {/*            borderColor: '#1B9749',*/}
                        {/*          }}*/}
                        {/*      />*/}
                        {/*    </View>*/}
                        {/*) : (*/}
                        {/*  <View*/}
                        {/*    style={{*/}
                        {/*      flexDirection: 'row',*/}
                        {/*      marginTop: 10,*/}
                        {/*      marginLeft: 20,*/}
                        {/*    }}>*/}
                        {/*    <View*/}
                        {/*      style={{backgroundColor: '#ffffff',width: 4,height: 16,marginRight: 2,*/}
                        {/*        borderWidth: 1,borderRadius: 2,borderColor: '#1B9749',}}*/}
                        {/*    />*/}
                        {/*    <View*/}
                        {/*      style={{*/}
                        {/*        backgroundColor: '#ffffff',*/}
                        {/*        width: 4,*/}
                        {/*        height: 16,*/}
                        {/*        marginRight: 2,*/}
                        {/*        borderWidth: 1,*/}
                        {/*        borderRadius: 2,*/}
                        {/*        borderColor: '#1B9749',*/}
                        {/*      }}*/}
                        {/*    />*/}
                        {/*    <View*/}
                        {/*      style={{*/}
                        {/*        backgroundColor: '#ffffff',*/}
                        {/*        width: 4,*/}
                        {/*        height: 16,*/}
                        {/*        marginRight: 2,*/}
                        {/*        borderWidth: 1,*/}
                        {/*        borderRadius: 2,*/}
                        {/*        borderColor: '#1B9749',*/}
                        {/*      }}*/}
                        {/*    />*/}
                        {/*    <View*/}
                        {/*      style={{*/}
                        {/*        backgroundColor: '#ffffff',*/}
                        {/*        width: 4,*/}
                        {/*        height: 16,*/}
                        {/*        marginRight: 2,*/}
                        {/*        borderWidth: 1,*/}
                        {/*        borderRadius: 2,*/}
                        {/*        borderColor: '#1B9749',*/}
                        {/*      }}*/}
                        {/*    />*/}
                        {/*    <View*/}
                        {/*      style={{*/}
                        {/*        backgroundColor: '#ffffff',*/}
                        {/*        width: 4,*/}
                        {/*        height: 16,*/}
                        {/*        marginRight: 2,*/}
                        {/*        borderWidth: 1,*/}
                        {/*        borderRadius: 2,*/}
                        {/*        borderColor: '#1B9749',*/}
                        {/*      }}*/}
                        {/*    />*/}
                        {/*    <View*/}
                        {/*      style={{*/}
                        {/*        backgroundColor: '#ffffff',*/}
                        {/*        width: 4,*/}
                        {/*        height: 16,*/}
                        {/*        borderWidth: 1,*/}
                        {/*        borderRadius: 2,*/}
                        {/*        borderColor: '#1B9749',*/}
                        {/*      }}*/}
                        {/*    />*/}
                        {/*  </View>*/}
                        {/*)}*/}
                      </View>
                    </View>
                  </View>
                  <View>
                    {/**我的余额**/}
                    <Text
                        style={{fontSize: 14, color: '#999999', marginTop: 8}}>
                      {locale?._('Pool.zyhy_mysy')}
                    </Text>
                    <Text
                        style={{
                          fontSize: 14,
                          color: '#F92360',
                          fontWeight: 'bold',
                          marginTop: 8,
                        }}>
                      {myMoney}
                    </Text>
                  </View>
                </View>
              </View>
              <TouchableOpacity onPress={()=>onCopy(itemContract)}>
              <View style={{height:1,backgroundColor:'#F3F2F3',marginTop:8,marginBottom:10,marginLeft:20,marginRight:20}}/>
              <View style={{flexDirection:'row',marginBottom:10}}>
                {/***打印图标+质押ID****/}
                <ImageBackground source={pool_print} style={{ width: 15, height:15, marginLeft:20,alignSelf:'center',alignItems:'center'}} />
                <Text style={{fontSize:13,color:"#ACACAC",marginLeft:5,fontWeight:"bold"}}>
                  {itemContract}
                </Text>
              </View>
              </TouchableOpacity>
            </View>
          </View>
          {/***添加三“添加” 按钮****/}
          <TouchableOpacity
            style={{
              width: 334,
              height: 40,
              justifyContent: 'center',
              backgroundColor: '#7367E3',
              alignItems: 'center',
              alignSelf: 'center',
              marginTop: 5,
              marginBottom:15,
              borderColor: '#7367E3',
              borderWidth: 1,
              borderRadius: 10,
            }}
            onPress={()=>
            {
              onPressAdd(addMoney)
            }
            }>
            <Text
              style={{
                // marginTop: 160,
                fontSize: 20,
                textAlign: 'center',
                color: 'white',
              }}>
              {locale?._('Pool.op.btn_create')}
            </Text>
          </TouchableOpacity>
          <Text style={{color:"#7367E3",marginLeft:"6%",marginRight:"6%",fontSize:15,marginBottom:30}}>
            {locale?._('pool.op.addTip')}
          </Text>
        </View>
      ) : null}


 {/*******转移--********/}
 {opState === '2' ? (
        <View>
          <View
            style={{
              marginTop: -40,
              minHeight: 380,
              marginLeft: 16,
              marginRight: 16,
              marginBottom: 16,
              backgroundColor: '#FFFFFF',
              borderColor: '#FFFFFF',
              borderRadius: 10,
              borderWidth: 1,
            }}>
            {/***转移凭证****/}
            <Text
              style={{
                fontSize: 18,
                color: '#14141A',
                fontWeight: 'bold',
                marginLeft: 16,
                marginTop: 8,
              }}>
              {locale?._('Pool.op.zypz')}
            </Text>
            {/***请输入凭证数量 ***/}
            <View
              style={{
                width: 300,
                height: 48,
                backgroundColor: '#ffffff',
                marginTop: 4,
                marginLeft: 12,
                borderWidth: 1,
                borderRadius: 10,
                borderColor: '#ffffff',
                flexDirection: 'row',
              }}>
              <TextInput
                underlineColorAndroid={'transparent'}
                placeholder={locale?._('Pool.op.pzcountHint')}
                value={transferPZ}
                onChangeText={(value) => {
                  setZyState('0');
                  // @ts-ignore
                  value = value.match(/^\d*(\.?\d{0,8})/g)[0];
                  setTransferPZ(value);
                  setTransferMoney(((parseFloat(value)/parseFloat(searchConsDetail[6])*parseFloat(searchConsDetail[3])).toString())=="NaN"?"" : ((parseFloat(value)/parseFloat(searchConsDetail[6])*parseFloat(searchConsDetail[3])).toString()));
                  }
                }
                style={{width: 250, fontSize: 17}}
              />
            </View>
            <View
              style={{
                height: 1,
                backgroundColor: '#F3F4F5',
                margin: 5,
                marginBottom: 10,
                marginLeft:15,
                marginRight:35
              }}
            />
            <View
              style={{
                flexDirection: 'row',
                justifyContent: "space-between",
                alignItems: 'center',
                marginLeft:15,
                marginRight:25
              }}>
              {/***25%****/}
              {zyState === '1' ? (
                <View
                  style={{
                    width: 68,
                    height: 30,
                    backgroundColor: '#F75367',
                    justifyContent: 'center',
                    alignItems: 'center',
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F75367',
                    marginRight: 10,
                  }}>
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#ffffff',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb25')}
                  </Text>
                </View>
              ) : (
                <TouchableOpacity
                  style={{
                    width: 68,
                    height: 30,
                    justifyContent: 'center',
                    alignItems: 'center',
                    marginRight: 10,
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F3F4F5',
                  }}
                  onPress={()=> {
                      setZyState('1')
                      setTransferPZ((0.25*parseFloat(searchConsDetail[5])).toString());
                      setTransferMoney((0.25*parseFloat(searchConsDetail[3])*(searchConsDetail[5]/parseFloat(searchConsDetail[6]))).toString())
                    }
                  }
                  >
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb25')}
                  </Text>
                </TouchableOpacity>
              )}

              {/***50%****/}
              {zyState === '2' ? (
                <View
                  style={{
                    width: 68,
                    height: 30,
                    backgroundColor: '#F75367',
                    justifyContent: 'center',
                    alignItems: 'center',
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F75367',
                    marginRight: 10,
                  }}>
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#ffffff',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb50')}
                  </Text>
                </View>
              ) : (
                <TouchableOpacity
                  style={{
                    width: 68,
                    height: 30,
                    justifyContent: 'center',
                    alignItems: 'center',
                    marginRight: 10,
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F3F4F5',
                  }}
                  onPress={()=>{
                    setZyState('2')
                    setTransferPZ((0.5*parseFloat(searchConsDetail[5])).toString());
                    setTransferMoney((0.5*parseFloat(searchConsDetail[3])*(searchConsDetail[5]/parseFloat(searchConsDetail[6]))).toString())
                  }}
                  >
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb50')}
                  </Text>
                </TouchableOpacity>
              )}

              {/***75%****/}
              {zyState === '3' ? (
                <View
                  style={{
                    width: 68,
                    height: 30,
                    backgroundColor: '#F75367',
                    justifyContent: 'center',
                    alignItems: 'center',
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F75367',
                    marginRight: 10,
                  }}>
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#ffffff',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb75')}
                  </Text>
                </View>
              ) : (
                <TouchableOpacity
                  style={{
                    width: 68,
                    height: 30,
                    justifyContent: 'center',
                    alignItems: 'center',
                    marginRight: 10,
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F3F4F5',
                  }}
                  onPress={()=>{
                    setZyState('3')
                    setTransferPZ((0.75*parseFloat(searchConsDetail[5])).toString());
                    setTransferMoney((0.75*parseFloat(searchConsDetail[3])*(searchConsDetail[5]/parseFloat(searchConsDetail[6]))).toString())
                  }}
                  >
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb75')}
                  </Text>
                </TouchableOpacity>
              )}

              {/***MAX****/}
              {zyState === '4' ? (
                <View
                  style={{
                    width: 68,
                    height: 30,
                    backgroundColor: '#F75367',
                    justifyContent: 'center',
                    alignItems: 'center',
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F75367',
                    marginRight: 10,
                  }}>
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#ffffff',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zbMax')}
                  </Text>
                </View>
              ) : (
                <TouchableOpacity
                  style={{
                    width: 68,
                    height: 30,
                    justifyContent: 'center',
                    alignItems: 'center',
                    marginRight: 10,
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F3F4F5',
                  }}
                  onPress={()=>{
                    setZyState('4')
                    setTransferPZ(searchConsDetail[5])
                    setTransferMoney((parseFloat(searchConsDetail[3])*(searchConsDetail[5]/parseFloat(searchConsDetail[6]))).toString())
                  }}
                  >
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zbMax')}
                  </Text>
                </TouchableOpacity>
              )}
            </View>
            {/***可用凭证****/}
            <View style={{flexDirection: 'row', margin: 10,marginLeft:15}}>
              <Text style={{fontSize: 14, color: '#8E8E8E'}}>
                {locale?._('Pool.op.kypz')}
                <Text style={{fontSize: 14, color: '#7367E3'}}>
                  {searchConsDetail[5]}
                </Text>
              </Text>
              {/***占比****/}
              {/*<Text*/}
              {/*  style={{*/}
              {/*    flex: 1,*/}
              {/*    fontSize: 14,*/}
              {/*    color: '#8E8E8E',*/}
              {/*    textAlign: 'right',*/}
              {/*    marginRight: 6,*/}
              {/*  }}>*/}
              {/*  {locale?._('Pool.op.zb')}*/}
              {/*  <Text style={{fontSize: 14, color: '#8E8E8E'}}>6%</Text>*/}
              {/*</Text>*/}
            </View>
            {/***转移资产****/}
            <Text
              style={{
                fontSize: 18,
                color: '#14141A',
                fontWeight: 'bold',
                marginLeft: 16,
                marginTop: 8,
              }}>
              {locale?._('Pool.op.zyzc')}
            </Text>
            {/***请输入资产金额 右边有一个SAT标识**/}
            <View
              style={{
                width: 300,
                height: 48,
                backgroundColor: '#ffffff',
                marginTop: 20,
                marginLeft: 12,
                borderWidth: 1,
                borderRadius: 10,
                borderColor: '#ffffff',
                flexDirection: 'row',
              }}>
              <TextInput
                underlineColorAndroid={'transparent'}
                placeholder={locale?._('Pool.op.zcmoneyHint')}
                // console.error(qh_zcmoneyError)
                value={formartMoney(transferMoney,8)}
                editable={false}
                style={{width: 240, fontSize: 20}}
              />
              <Text
                style={{
                  fontSize: 16,
                  color: '#9A9AA7',
                  alignSelf:"center",
                  borderWidth: 1,
                  borderColor: '#9A9AA7',
                  borderRadius: 10,
                  paddingLeft: 10,
                  paddingRight: 10,
                  paddingTop: 2,
                  paddingBottom: 2,
                  marginRight: 0,
                }}>
                SAT
              </Text>
            </View>

              {/***转移至****/}
              <Text
              style={{
                fontSize: 18,
                color: '#14141A',
                fontWeight: 'bold',
                marginLeft: 16,
                marginTop: 8,
              }}>
              {locale?._('Pool.op.zyz')}
            </Text>
            {/***请输入资产金额 右边有一个SAT标识**/}
            <View
              style={{
                width: 300,
                height: 48,
                backgroundColor: '#ffffff',
                marginTop: 20,
                marginLeft: 12,
                borderWidth: 1,
                borderRadius: 10,
                borderColor: '#ffffff',
                flexDirection: 'row',
              }}>
              <TextInput
                underlineColorAndroid={'transparent'}
                placeholder={locale?._('Pool.op.hyaddrHint')}
                value={transferContract}
                onChangeText={(value) => setTransferContract(value)}
                style={{width: 280, fontSize: 12}}
              />
            </View>

            <View
              style={{
                height: 1,
                backgroundColor: '#F3F4F5',
                margin: 5,
                marginBottom: 10,
                marginLeft:15,
                marginRight:35
              }}
            />
            {/***转移****/}
            <TouchableOpacity
                onPress={()=>onPressMove(transferPZ)}
                style={{marginTop:10,marginBottom:15,width: 320,height: 40,justifyContent: 'center',backgroundColor: '#7367E3',
                alignSelf: 'center',borderColor: '#7367E3',borderWidth: 1,borderRadius: 10,
              }}>
              <Text
                style={{
                  fontSize: 20,
                  textAlign: 'center',
                  color: 'white',
                }}>
                {locale?._('Pool.op.btn_modife')}
              </Text>
            </TouchableOpacity>
          </View>
          <View style={{height:40,marginLeft:18,marginTop:2,marginBottom:40}}>
            <Text style={{color:"#734FDFFF"}}>{locale?._('pool.op.Notice')}</Text>
          </View>
        </View>
      ) : null}

      {/*******取回界面--********/}
      {opState === '3' ? (
        <View>
          <View
            style={{
              marginTop: -40,
              minHeight: 340,
              marginLeft: 16,
              marginRight: 16,
              marginBottom: 16,
              backgroundColor: '#FFFFFF',
              borderColor: '#FFFFFF',
              borderRadius: 10,
              borderWidth: 1,
            }}>
            {/***取回凭证****/}
            <Text
              style={{
                fontSize: 18,
                color: '#14141A',
                fontWeight: 'bold',
                marginLeft: 16,
                marginTop: 8,
              }}>
              {locale?._('Pool.op.qhpz')}
            </Text>
            {/***请输入凭证数量 ***/}
            <View
              style={{
                width: 300,
                height: 48,
                backgroundColor: '#ffffff',
                marginTop: 4,
                marginLeft: 12,
                borderWidth: 1,
                borderRadius: 10,
                borderColor: '#ffffff',
                flexDirection: 'row',
              }}>
              <TextInput
                underlineColorAndroid={'transparent'}
                placeholder={locale?._('Pool.op.pzcountHint')}
                // errorMessage={addMoneyError}
                // value={receiveBackProofCount}

                onChangeText={
                  (value) =>
                  {
                    // @ts-ignore
                    value = value.match(/^\d*(\.?\d{0,8})/g)[0];
                    setQhState('0')
                    //console.log("change Value ==>"+value)
                    setReceiveBackProofCount(value)

                    //console.log(receiveBackProofCount)
                    updateReceiveBackProofCount(value)
                  }
                }
                style={{width: 250, fontSize: 17}}
              >
              {
                qh_qhpzcountPercent?qh_qhpzcountPercent:''
              }
              </TextInput>
            </View>
            <View
              style={{
                height: 1,
                backgroundColor: '#F3F4F5',
                margin: 5,
                marginBottom: 10,
                marginLeft:15,
                marginRight:35
              }}
            />

            <View
              style={{
                flexDirection: 'row',
                justifyContent: "space-between",
                alignItems: 'center',
                marginLeft:15,
                marginRight:25
              }}>
              {/***25%****/}
              {qhState === '1' ? (
                <View
                  style={{
                    width: 68,
                    height: 30,
                    backgroundColor: '#F75367',
                    justifyContent: 'center',
                    alignItems: 'center',
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F75367',
                    marginRight: 10,
                  }}>
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#ffffff',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb25')}
                  </Text>
                </View>
              ) : (
                <TouchableOpacity
                  style={{
                    width: 68,
                    height: 30,
                    justifyContent: 'center',
                    alignItems: 'center',
                    marginRight: 10,
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F3F4F5',
                  }}
                  onPress={
                  ()=>{
                     setQhState('1')
                    ,setQh_qhpzcountPercent((searchConsDetail[5]?searchConsDetail[5]*0.25:0)+'')
                    calculateMyIncome(0.25)
                  }
                  }
                  >
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb25')}
                  </Text>
                </TouchableOpacity>
              )}

              {/***50%****/}
              {qhState === '2' ? (
                <View
                  style={{
                    width: 68,
                    height: 30,
                    backgroundColor: '#F75367',
                    justifyContent: 'center',
                    alignItems: 'center',
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F75367',
                    marginRight: 10,
                  }}>
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#ffffff',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb50')}
                  </Text>
                </View>
              ) : (
                <TouchableOpacity
                  style={{
                    width: 68,
                    height: 30,
                    justifyContent: 'center',
                    alignItems: 'center',
                    marginRight: 10,
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F3F4F5',
                  }}
                  onPress={()=>{
                    setQhState('2')
                    ,setQh_qhpzcountPercent((searchConsDetail[5]?searchConsDetail[5]*0.50:0)+'')
                    ,calculateMyIncome(0.5)
                  }}
                  >
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb50')}
                  </Text>
                </TouchableOpacity>
              )}

              {/***75%****/}
              {qhState === '3' ? (
                <View
                  style={{
                    width: 68,
                    height: 30,
                    backgroundColor: '#F75367',
                    justifyContent: 'center',
                    alignItems: 'center',
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F75367',
                    marginRight: 10,
                  }}>
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#ffffff',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb75')}
                  </Text>
                </View>
              ) : (
                <TouchableOpacity
                  style={{
                    width: 68,
                    height: 30,
                    justifyContent: 'center',
                    alignItems: 'center',
                    marginRight: 10,
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F3F4F5',
                  }}
                  onPress={()=>
                    {setQhState('3')
                    ,setQh_qhpzcountPercent((searchConsDetail[5]?searchConsDetail[5]*0.75:0)+'')
                    ,calculateMyIncome(0.75)
                  }
                  }
                  >
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zb75')}
                  </Text>
                </TouchableOpacity>
              )}

              {/***MAX****/}
              {qhState === '4' ? (
                <View
                  style={{width: 68,
                    height: 30,
                    backgroundColor: '#F75367',
                    justifyContent: 'center',
                    alignItems: 'center',
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F75367',
                    marginRight: 10,
                  }}>
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#ffffff',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zbMax')}
                  </Text>
                </View>
              ) : (
                <TouchableOpacity
                  style={{
                    width: 68,
                    height: 30,
                    justifyContent: 'center',
                    alignItems: 'center',
                    marginRight: 10,
                    borderRadius: 2,
                    borderWidth: 2,
                    borderColor: '#F3F4F5',
                  }}
                  onPress={
                    ()=>
                    {
                    setQhState('4')
                    ,setQh_qhpzcountPercent((searchConsDetail[5]?searchConsDetail[5]:0)+'')
                    ,calculateMyIncome(1)
                    }
                  }
                  >
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      textAlign: 'center',
                    }}>
                    {locale?._('Pool.op.zbMax')}
                  </Text>
                </TouchableOpacity>
              )}
            </View>
            {/***可用凭证****/}
            <View style={{flexDirection: 'row', margin: 10}}>
              <Text style={{marginLeft: 6,fontSize: 14, color: '#8E8E8E'}}>
                {locale?._('Pool.op.kypz')}
                <Text style={{fontSize: 14, color: '#7367E3'}}>
                  {searchConsDetail[5]?searchConsDetail[5]:0}
                </Text>
              </Text>
              {/***占比****/}
              {/*<Text*/}
              {/*  style={{*/}
              {/*    flex: 1,*/}
              {/*    fontSize: 14,*/}
              {/*    color: '#8E8E8E',*/}
              {/*    textAlign: 'right',*/}
              {/*    marginRight: 6,*/}
              {/*  }}>*/}
              {/*  {locale?._('Pool.op.zb')}*/}
              {/*  <Text style={{fontSize: 14, color: '#8E8E8E'}}>*/}
              {/*  {searchConsDetail[5]?searchConsDetail[6]?(searchConsDetail[5]/searchConsDetail[6]*100).toString().length > 9*/}
              {/*  ?(searchConsDetail[5]/searchConsDetail[6]*100).toString().substring(0,9)*/}
              {/*  :(searchConsDetail[5]/searchConsDetail[6]*100):0:0}%*/}
              {/*  </Text>*/}
              {/*</Text>*/}
            </View>
            {/***取回资产****/}
            <Text
              style={{
                fontSize: 18,
                color: '#14141A',
                fontWeight: 'bold',
                marginLeft: 16,
                marginTop: 8,
              }}>
              {locale?._('Pool.op.qhzc')}
            </Text>
            {/***请输入资产金额 右边有一个SAT标识**/}
            <View
              style={{
                width: 300,
                height: 48,
                backgroundColor: '#ffffff',
                marginTop: 20,
                marginLeft: 12,
                borderWidth: 1,
                borderRadius: 10,
                borderColor: '#ffffff',
                flexDirection: 'row',
              }}>
              <TextInput
                underlineColorAndroid={'transparent'}
                editable={false}
                // placeholder={locale?._('Pool.op.zcmoneyHint')}
                // errorMessage={qh_zcmoneyError}
                // onChangeText={(value) => setQh_zcmoney(value)}
                style={{width: 240, fontSize: 20, color:'black'}}
              >
                {
                qh_zcmoney
                }
              </TextInput>
              <Text
                style={{
                  fontSize: 16,
                  color: '#9A9AA7',
                  alignSelf: 'center',
                  borderWidth: 1,
                  borderColor: '#9A9AA7',
                  borderRadius: 10,
                  paddingLeft: 10,
                  paddingRight: 10,
                  paddingTop: 2,
                  paddingBottom: 2,
                  marginRight: 10,
                }}>
                SAT
              </Text>
            </View>

            <View
              style={{
                height: 1,
                backgroundColor: '#F3F4F5',
                margin: 5,
                marginBottom: 10,
                marginLeft:15,
                marginRight:35
              }}
            />
            {/***取回****/}
            <TouchableOpacity
              style={{
                width: 320,
                height: 40,
                justifyContent: 'center',
                marginTop:10,
                marginBottom:15,
                backgroundColor: '#7367E3',
                alignSelf: 'center',
                borderColor: '#7367E3',
                borderWidth: 1,
                borderRadius: 10,
              }}
              onPress={()=>
                {
                  onPressQhOne(receiveBackProofCount)
                }
                }
              >
              <Text
                style={{
                  // marginTop: 160,
                  fontSize: 20,
                  textAlign: 'center',
                  color: 'white',
                }}>
                {locale?._('Pool.op.btn_delete')}
              </Text>
            </TouchableOpacity>
          </View>

          {/* ******取回二******* */}
          {
          qhTwoListShow == true?
         <View>
            <View>
              {/***取回状态[遮罩层的颜色：背景色：7F7F7F  、按钮颜色 000000  、按钮文字颜色 FFFFFF]****/}
              <Text
                style={{
                  fontSize: 18,
                  color: '#14141A',
                  fontWeight: 'bold',
                  marginLeft: 16,
                  marginTop: 8,
                  marginBottom: 8,
                }}>
                {locale?._('Pool.op.qhzt')}
              </Text>
            </View>
            {/******有一个，遮罩效果，显示“确认取回”按钮*********/}
            <View
              style={{
                backgroundColor: 'white',
                borderColor: 'white',
                borderWidth: 1,
                borderRadius: 20,
                margin: 10,
                minHeight: 78,
              }}>
            <View>
              <View style={{flexDirection: 'row',alignSelf:'center',flex:1,justifyContent:'center',alignItems:'center'}}>
                <View style={{flex: 1}}>
                  {/***序号***/}
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      marginLeft: 25,
                      marginTop: 10,
                      alignSelf:'center',
                    }}>
                    {locale?._('Pool.op.xh')}
                  </Text>

                </View>
                <View style={{flex: 1}}>
                  {/***金额***/}
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      marginLeft: 10,
                      marginTop: 10,
                      alignSelf:'center',
                    }}>
                    {locale?._('Pool.op.je')}
                  </Text>

                </View>
                <View style={{flex: 1}}>
                  {/**状态**/}
                  <Text
                    style={{
                      fontSize: 12,
                      color: '#8E8E8E',
                      marginLeft: 10,
                      marginTop: 10,
                      alignSelf:'center',
                    }}>
                    {locale?._('Pool.op.zt')}
                  </Text>
                </View>
                <View style={{flex: 1}}>
                  {/**撤回**/}
                  <Text
                      style={{
                        fontSize: 12,
                        color: '#8E8E8E',
                        marginLeft: 10,
                        marginTop: 10,
                        alignSelf:'center',
                      }}>
                    {locale?._('Pool.op.recall')}
                  </Text>

                </View>
              </View>
              {
                qhTwoList.map((item:any,index:any)=>(
                    <View key={index} style={{flexDirection: 'row',alignSelf:'center',flex:1,justifyContent:'center',alignItems:'center'}}>
                      <View style={{flex:1,alignItems:"center",justifyContent:"center"}}>
                        <Text
                            style={{
                              fontSize: 14,
                              color: '#14141A',
                              marginLeft: 16,
                              marginTop: 15,
                              fontWeight: 'bold',
                              alignSelf:'center',
                            }}>
                          {item.LockHeight}
                        </Text>
                      </View>
                      <View style={{flex:1,alignItems:"center",justifyContent:"center"}}>
                        <Text
                            style={{fontSize: 12,color: '#14141A', marginLeft: 0, marginTop:15,
                              fontWeight: 'bold',alignSelf:'center',
                            }}>
                          {
                            item.Amount
                          }
                        </Text>
                      </View>
                      <View style={{flex:1,alignItems:"center",justifyContent:"center"}}>
                        <TouchableOpacity style={{alignItems:"center",width:60,height:24,backgroundColor:"#77B844",justifyContent:"center",marginTop:12,borderColor:"#63A62F",borderRadius:10,borderWidth:1}}
                          onPress={()=>
                            {
                              if(getRemainTime(item.LockHeight) == locale?._('pool.op.Retrieve')){
                                onPressQhTwo(item.LockHeight,item.Amount)
                              }else{
                                Alert.alert('',  locale?._('pool.op.getLater'),[{text: (locale?._('Assets.send.OK') as any)}]);
                              }
                            }
                          }>
                        <Text
                            style={{fontSize: 11,color: '#fff',flex:1,alignSelf:'center',alignItems:"center",justifyContent:"center", marginTop:4}}>
                          {getRemainTime(item.LockHeight)}
                        </Text>
                        </TouchableOpacity>
                      </View>

                      <View style={{flex:1,alignItems:"center",justifyContent:"center"}}>
                        <TouchableOpacity style={{alignItems:"center",width:60,height:24,backgroundColor:"#f0ad4e",justifyContent:"center",marginTop:12,borderColor:"#f0ad4e",borderRadius:10,borderWidth:1}}
                                          onPress={()=>
                                            {
                                              Alert.alert("",locale?._('pool.zyhy.decideRecallHY'),[{
                                                text: locale?._('cancel'),
                                                onPress: () => console.log("Cancel Recall"),
                                                style: "cancel"
                                              }, {
                                                text: locale?._('ok'),
                                                onPress: async () => {
                                                  recallContract(item.LockHeight,item.Amount);
                                                }
                                              }])

                                            }
                                          }>
                          <Text
                              style={{fontSize: 11,color: '#fff',flex:1,alignSelf:'center',alignItems:"center",justifyContent:"center", marginTop:4}}>
                            {locale?._('Pool.op.recall')}
                          </Text>
                        </TouchableOpacity>
                      </View>
                    </View>

                ))
              }

            </View>



              {/*<View*/}
              {/*  style={{*/}
              {/*    height: 1,*/}
              {/*    backgroundColor: '#F3F4F5',*/}
              {/*    margin: 5,*/}
              {/*    marginBottom: 5,*/}
              {/*  }}*/}
              {/*/>*/}
            </View>
          </View>
          //{/* 二次取回ViewEnd */}
        :null
      }
        </View>
      ) : null}
      {/* @ts-ignore*/}
      <WaitingModal show={bshow} prompt={prompt} />
      {/***2021-03-06*/}
      {/* @ts-ignore*/}
      <LoadingView showLoading={bShowLoading} />
      {/***2021-03-06*/}
      <AuthDialog visible={authDialogVisible} onClose={onAuthDialogClose} />
      {/* 显示密码 */}
    </View>
    </ScrollView>
  );
};

export default PoolOp;
